package com.ruoyi.logistic.service.impl;

import com.github.pagehelper.PageHelper;
import com.ruoyi.common.domain.vo.TableVo;
import com.ruoyi.logistic.domain.NetworkUndertakeCentreAssessmentCollect;
import com.ruoyi.logistic.domain.NetworkUndertakeCentreAssessmentDetail;
import com.ruoyi.logistic.domain.PageDate;
import com.ruoyi.logistic.domain.vo.NetworkUndertakeCentreAssessmentCollectVo;
import com.ruoyi.logistic.domain.vo.NetworkUndertakeCentreAssessmentDetailVo;
import com.ruoyi.logistic.enums.NetworkUndertakeCentreAssessmentCollectEnum;
import com.ruoyi.logistic.enums.NetworkUndertakeCentreAssessmentDetailEnum;
import com.ruoyi.logistic.enums.NetworkUndertakeCentreTransferCollectEnum;
import com.ruoyi.logistic.enums.NetworkUndertakeCentreTransferDetailEnum;
import com.ruoyi.logistic.mapper.NetworkUndertakeCentreAssessmentCollectMapper;
import com.ruoyi.logistic.mapper.NetworkUndertakeCentreAssessmentDetailMapper;
import com.ruoyi.logistic.service.NetworkUndertakeCentreAssessmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class NetworkUndertakeCentreAssessmentServiceImpl implements NetworkUndertakeCentreAssessmentService {
    @Autowired
    private NetworkUndertakeCentreAssessmentDetailMapper networkUndertakeCentreAssessmentDetailMapper;
    @Autowired
    private NetworkUndertakeCentreAssessmentCollectMapper networkUndertakeCentreAssessmentCollectMapper;
    @Override
    public List<NetworkUndertakeCentreAssessmentDetail> selectAll(PageDate pageDate) {
        PageHelper.startPage(pageDate);
        return networkUndertakeCentreAssessmentDetailMapper.selectAll();
    }

    @Override
    public Boolean insert(NetworkUndertakeCentreAssessmentDetail networkUndertakeCentreAssessmentDetail) {
        return networkUndertakeCentreAssessmentDetailMapper.insert(networkUndertakeCentreAssessmentDetail);
    }

    @Override
    public Boolean update(NetworkUndertakeCentreAssessmentDetail networkUndertakeCentreAssessmentDetail) {
        return networkUndertakeCentreAssessmentDetailMapper.update(networkUndertakeCentreAssessmentDetail);
    }

    @Override
    public Boolean deleteById(Integer id) {
        return networkUndertakeCentreAssessmentDetailMapper.deleteById(id);
    }

    @Override
    public List<NetworkUndertakeCentreAssessmentDetail> search(NetworkUndertakeCentreAssessmentDetailVo networkUndertakeCentreAssessmentDetailVo) {
        PageHelper.startPage(networkUndertakeCentreAssessmentDetailVo.getPageDate());
        return networkUndertakeCentreAssessmentDetailMapper.search(networkUndertakeCentreAssessmentDetailVo);
    }

    @Override
    public List<NetworkUndertakeCentreAssessmentCollect> assessmentCollect(NetworkUndertakeCentreAssessmentCollectVo networkUndertakeCentreAssessmentCollectVo) {
        PageHelper.startPage(networkUndertakeCentreAssessmentCollectVo.getPageDate());

        List<NetworkUndertakeCentreAssessmentCollect> assessmentCollects = networkUndertakeCentreAssessmentCollectMapper.assessmentCollect(networkUndertakeCentreAssessmentCollectVo);
        assert assessmentCollects != null;
        for (NetworkUndertakeCentreAssessmentCollect assessmentCollect : assessmentCollects){
                assessmentCollect.setAuditDate(networkUndertakeCentreAssessmentCollectVo.getMonth());
        }
        return assessmentCollects;
    }

    @Override
    public List<TableVo> initTable() {
        List<TableVo> list = new ArrayList<>();
        TableVo tableVo = new TableVo();
        String[] fields = {"statisticsDate", "transportCode", "assessmentAmount", "firstOrderType", "secondOrderType", "scanType"
                , "scanner", "assessmentReasonRemark", "orderClient"
        };
        for (String field : fields) {
            tableVo = new TableVo();
            tableVo.setFields(field);
            list.add(tableVo);
        }
        for (TableVo vo : list) {
            vo.setTranslate(NetworkUndertakeCentreAssessmentDetailEnum.getValue(vo.getFields()));
        }
        return list;
    }

    @Override
    public List<TableVo> initTableCollect() {
        List<TableVo> list = new ArrayList<>();
        TableVo tableVo = new TableVo();
        String[] fields = {"auditDate", "ticket", "preAmountReceived", "afterRemissionAssessmentAmount", "deductionAmount", "totalAssessment"
                , "osLogisticsInformation", "unWeighedExamine", "falseSignature","triplexLose","triplexDelay","triplexWorn"
                , "operateComplain", "webmasterComplain", "otherExamine"
        };
        for (String field : fields) {
            tableVo = new TableVo();
            tableVo.setFields(field);
            list.add(tableVo);
        }
        for (TableVo vo : list) {
            vo.setTranslate(NetworkUndertakeCentreAssessmentCollectEnum.getValue(vo.getFields()));
        }
        return list;
    }
}
